package com.party.core.service.gift.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.gift.GiftMemberReadDao;
import com.party.core.dao.write.gift.GiftMemberWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.gift.GiftMember;
import com.party.core.service.gift.IGiftMemberService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @author： yifeng
 * @description： 礼包和用户的关系
 * @date：Created in  2017/12/16 上午 10:42
 **/
@Service
public class GiftMemberService implements IGiftMemberService {
    @Autowired
    private GiftMemberReadDao giftMemberReadDao;
    @Autowired
    private GiftMemberWriteDao giftMemberWriteDao;

    @Override
    public String insert(GiftMember t) {
        BaseModel.preInsert(t);
        boolean result = giftMemberWriteDao.insert(t);
        if (result) {
            return t.getId();
        }
        return null;
    }

    @Override
    public boolean update(GiftMember t) {
        t.setUpdateDate(new Date());
        return giftMemberWriteDao.update(t);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return giftMemberWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return giftMemberWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return giftMemberWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return giftMemberWriteDao.batchDelete(ids);
    }

    @Override
    public GiftMember get(String id) {
        return giftMemberReadDao.get(id);
    }

    @Override
    public List<GiftMember> listPage(GiftMember t, Page page) {
        return giftMemberReadDao.listPage(t, page);
    }

    @Override
    public List<GiftMember> list(GiftMember t) {
        return giftMemberReadDao.listPage(t, null);
    }

    @Override
    public List<GiftMember> batchList(Set<String> ids, GiftMember t, Page page) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.EMPTY_LIST;
        }
        return giftMemberReadDao.batchList(ids, new HashedMap(), page);
    }

    @Override
    public GiftMember getUnique(GiftMember giftMember) {
        return giftMemberReadDao.getUnique(giftMember);
    }

    @Override
    public void deleteByGiftId(String giftId) {
        giftMemberWriteDao.deleteByGiftId(giftId);
    }
}
